Skip to content

Remove SPIAwareTrait and adopt TestScoping in its place #901

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Jan 9, 2025

Conversation

stmontgomery
Copy link
Contributor

@stmontgomery stmontgomery commented Jan 8, 2025

This is a follow-on from #733 which introduced the Test Scoping Traits feature. As that proposal indicated, the SPIAwareTrait SPI protocol is no longer necessary, so this PR removes it and adopts TestScoping in its place.

Motivation:

Adopting Test Scoping Traits for the purpose which SPIAwareTrait previously served simplifies a lot of runner and planning logic.

Modifications:

  • Delete SPIAwareTrait and related SPI.
  • Adopt TestScoping in ParallelizationTrait instead.
  • Changed ParallelizationTrait to not always have the value true for isRecursive. Test Scoping Traits makes this no longer necessary: the invocation of children of any suites which have .serialized is scoped to have parallelization disabled.
  • Removed tracking of isParallelizationEnabled on the Runner.Plan.Action.RunOptions type. For now, I kept the RunOptions struct, since it could be useful in the future and it's SPI.
  • Removed obsolete logic in Runner for propagating ancestor steps, and refactored slightly to make many things static. This is to help ensure certain functions don't access the self.configuration property when instead they should be accessing Configuration.current.

Result:

No functional change, but implementation is simplified.

Checklist:

  • Code and documentation should follow the style of the Style Guide.
  • If public symbols are renamed or modified, DocC references should be updated.

@stmontgomery stmontgomery added enhancement New feature or request traits Issues and PRs related to the trait subsystem or built-in traits labels Jan 8, 2025
@stmontgomery stmontgomery self-assigned this Jan 8, 2025
@stmontgomery
Copy link
Contributor Author

@swift-ci please test

@stmontgomery stmontgomery changed the title Deprecate the SPIAwareTrait SPI protocol and adopt TestScoping in its place Deprecate SPIAwareTrait and adopt TestScoping in its place Jan 8, 2025
/// This trait is recursively applied: if it is applied to a suite, any
/// parameterized tests or test suites contained in that suite are also
/// serialized (as are any tests contained in those suites, and so on.)
/// If this trait is applied to a suite, any test functions or test suites
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's important to note that parameterized test functions are serialized (as opposed to just function A, function B, function C get serialized.)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll try to tweak the wording more. What I was attempting to clarify with this re-wording is that regular, non-parameterized test functions within a suite which has .serialized are also serialized alongside any sub-suites which are their peers. I found the existing wording a bit unclear about the handling of non-parameterized test functions.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I recall this being difficult to get right the last time too—might want to ping @iamleeg & friends for assistance?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've pushed a new phrasing in the mean time

@stmontgomery stmontgomery changed the title Deprecate SPIAwareTrait and adopt TestScoping in its place Remove SPIAwareTrait and adopt TestScoping in its place Jan 8, 2025
@stmontgomery
Copy link
Contributor Author

@swift-ci please test

@stmontgomery stmontgomery requested a review from grynspan January 8, 2025 21:58
}
}

if let step = stepGraph.value, case .run = step.action {
await Test.withCurrent(step.test) {
_ = await Issue.withErrorRecording(at: step.test.sourceLocation, configuration: configuration) {
_ = await Issue.withErrorRecording(at: step.test.sourceLocation, configuration: _configuration) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we update withErrorRecording to just pull the current task-local value? Do we ever use it in a way that needs to take any other value?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given where I landed with other changes I don't think I'll need this right now

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But I agree in principle we could make that utility infer the current configuration, just not sure it's needed for this PR

@stmontgomery
Copy link
Contributor Author

@swift-ci please test

@stmontgomery stmontgomery requested a review from grynspan January 8, 2025 23:16
@stmontgomery stmontgomery merged commit 801d5ea into swiftlang:main Jan 9, 2025
3 checks passed
@stmontgomery stmontgomery deleted the deprecate-SPIAwareTrait branch January 9, 2025 20:50
stmontgomery added a commit that referenced this pull request Mar 13, 2025
…ot to avoid decoding error in clients (#1023)

This fixes a regression in the encoding of the `Runner.Plan` snapshot
types, which can manifest when using Xcode 16.

### Motivation:

The `isParallelizationEnabled` property was deprecated and changed from
a stored property to a derived one in #901. That caused the value to no
longer be encoded in `Runner.Plan.Action.RunOptions`, which can cause
decoding errors in versions of Xcode which expect it to still be
present.

### Modifications:

- Manually implement `Codable` conformance for the affected type to
begin including a hardcoded value.

### Checklist:

- [x] Code and documentation should follow the style of the [Style
Guide](https://github.com/apple/swift-testing/blob/main/Documentation/StyleGuide.md).
- [x] If public symbols are renamed or modified, DocC references should
be updated.

Fixes rdar://146284519
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request traits Issues and PRs related to the trait subsystem or built-in traits
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants